﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc @Copy Right 2020
// 文件： LiveCommentRepository.cs
// 项目名称：斑马车务
// 创建时间：2020/2/24
// 负责人：lsc
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using YouWei.Infrastructure.Entity;
using YouWei.Infrastructure.Models;
using Dapper.Extensions;
using Dapper;

namespace YouWei.Infrastructure.Repository
{
	/// <summary>
	/// 仓储层
	/// </summary>	
	public class LiveCommentRepository:BaseRepository<LiveComment>
	{		
    
        #region 构造

        public LiveCommentRepository() : base(){}

        public LiveCommentRepository(string connectionString) : base(connectionString){}

        public LiveCommentRepository(DatabaseContext dbContext) : base(dbContext){}

        #endregion

        /// <summary>
        /// 分页查询，带条件
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="condition"></param>
        /// <returns></returns>
        public Page<LiveCommentDto> GetPages(int pageIndex, long pageSize, ReqLiveCommentCondition condition)
        {
            StringBuilder sql = new StringBuilder("SELECT lc.*,wcu.NickName FROM LiveComment lc WITH(NOLOCK) INNER JOIN WeChartUser wcu ON lc.WeChartUserID=wcu.WeChartUserID where IsActive =1");
            if (!string.IsNullOrWhiteSpace(condition.StartDate))
            {
                sql.Append(" AND CreatedTime>@StartDate");
            }
            if (!string.IsNullOrWhiteSpace(condition.EndDate))
            {
                sql.Append(" AND CreatedTime<@EndDate");
            }
            if (condition.RoomId>0)
            {
                sql.Append(" AND RoomID=@RoomID");
            }

            DynamicParameters dparams = new DynamicParameters();
            dparams.Add("@RoomID", condition.RoomId, System.Data.DbType.Int32);
            dparams.Add("@StartDate", condition.StartDate, System.Data.DbType.String);
            dparams.Add("@EndDate", condition.EndDate, System.Data.DbType.String);
            return dbContext.Connection.Page<LiveCommentDto>(pageIndex, pageSize, sql.ToString(), dparams);
        }
    }
}